package com.soilflow.web.controller.auction;

import com.soilflow.common.core.controller.BaseController;
import com.soilflow.common.core.domain.AjaxResult;
import com.soilflow.common.core.page.TableDataInfo;
import com.soilflow.common.domain.LandAuctionPrice;
import com.soilflow.common.domain.dto.LandAuctionPriceDto;
import com.soilflow.common.domain.vo.LandAuctionPriceVo;
import com.soilflow.info.service.LandAuctionPriceService;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.util.List;

/**
 * 竞拍价格表
 */
@RestController
@RequestMapping("/auction/price")
public class LandAuctionPriceController extends BaseController {

    @Autowired
    private LandAuctionPriceService landAuctionPriceService;


    /**
     * 竞拍出价列表
     * @param dto
     * @return
     */
    @GetMapping("/list")
    public TableDataInfo auctionPriceList(LandAuctionPriceDto dto){
        startPage();
        List<LandAuctionPriceVo> list = landAuctionPriceService.auctionPriceList(dto);
        return getDataTable(list);
    }

    /**
     * 设置中标，取消中标
     */
    @GetMapping("/{id}")
    public AjaxResult isSuccessfulBidder(@PathVariable Long id){
        LandAuctionPrice byId = landAuctionPriceService.getById(id);
        if (byId.getIsSuccessfulBidder().equals("0")){
            byId.setIsSuccessfulBidder("1");
        }else {
            byId.setIsSuccessfulBidder("0");
        }
        landAuctionPriceService.updateById(byId);
        return AjaxResult.success();
    }



    /**
     * 删除竞拍出价列表
     * @param ids
     * @return
     */
    @DeleteMapping("/del/{ids}")
    public AjaxResult delAuctionPrice(@PathVariable List<Long> ids){
        landAuctionPriceService.removeByIds(ids);
        return AjaxResult.success();
    }

    /**
     * 插入竞拍出价表
     * @param dto
     * @return
     */
    @GetMapping("/add")
    public AjaxResult addAuctionPrice( LandAuctionPriceDto dto) throws ParseException {
        System.out.println("dto = " + dto);
        Boolean result = landAuctionPriceService.addAuctionPrice(dto);
        if (result){
            return AjaxResult.success();
        }else {
            return AjaxResult.error();
        }
    }





}
